package com.huan.vertxle.initialization;

import com.huan.vertxle.model.ConfigParams;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.Slf4JLoggerFactory;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;

/**
 * 配置初始化
 *
 * @author huan
 */
public class StartParamsInit {
  private static final InternalLogger LOGGER = Slf4JLoggerFactory.getInstance(StartParamsInit.class);
  public static ConfigParams init = null;

  public static void initParams(JsonObject event) {
    try {
      JsonObject entries = new JsonObject();
      entries.put("service", event.getJsonObject("service"));
      entries.put("websocket", event.getJsonObject("websocket"));
      entries.put("redis", event.getJsonObject("redis"));
      entries.put("postgre", event.getJsonObject("postgre"));
      StartParamsInit.init = entries.mapTo(ConfigParams.class);
      // redis pgsql初始化
      new RedisInit().init();
      new PgSqlInit().init();
    } catch (Exception e) {
      LOGGER.error("初始化参数失败:{}", e.getMessage());
      Vertx.currentContext().owner().close();
    }
  }
}
